package galaxy;

import irio.gamer.gamer;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import Logic.Galaxy;
import Logic.GamerParams;

import utils.JDouble;
import utils.JMyCombo;
import utils.JTripleValue;
import utils.JVector;
import utils.Vec;

public class GalaxyPanel extends JPanel {

	
	JLabel lblFilename = new JLabel();
	
	public String getLabel() {
		return "Galaxy file: " + gamer.galaxy.filename;
	}

	public JButton btnNew = new JButton("New");

	
	
	int returnVal;
	public JPanel filePanel() {
		JPanel p = new JPanel();
		p.setLayout(new GridLayout(3,1));
		p.add(lblFilename);
		lblFilename.setText(getLabel());
		JButton btnLoad = new JButton("Load");
		p.add(btnLoad);
		p.add(btnNew);
		
		btnNew.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				String s = (String)JOptionPane.showInputDialog(
				                    gamer.galaxyPanel,
				                    "Enter a galaxy name (without extension)");

				//If a string was returned, say so.
				if ((s != null) && (s.length() > 0)) {
					Galaxy newGalaxy = new Galaxy();
					newGalaxy.initialized = true;
					newGalaxy.Save(s + ".gax");
					gamer.reload( s + ".gax");
				    return;
				}

			}
		});
		
		
		btnLoad.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				gamer.loadGalaxy();
				//In response to a button click:
				
			}
		});
		
		return p;
	}
	
	public GalaxyPanel() {
		setLayout(new GridLayout(4,2));
		Galaxy g = gamer.galaxy;
		
		add(filePanel());
		JVector jvOrientation = new JVector("Galaxy orientation", g.orientation, new Vec(-1, -1, -1), new Vec(1,1,1), GamerParams.decimal);
		jvOrientation.normalized = true;
		add(jvOrientation);
		add(new JVector("Galaxy axis", g.axis, new Vec(-1, -1, -1), new Vec(1,1,1), GamerParams.decimal));
		add(new JVector("Galaxy bulge axis", g.bulge_axis, new Vec(-5, -5, -5), new Vec(5,5,5), GamerParams.decimal));
		JDouble no_arms = new JDouble("Number of arms", g.no_arms, new Vec(0, 0, 0), new Vec(4,0,0), GamerParams.integer);
		JDouble arm1 = new JDouble("Arm 1", g.arm1, new Vec(0, 0, 0), new Vec(3.14159*2.0,0,0), GamerParams.decimal);
		JDouble arm2 = new JDouble("Arm 2", g.arm2, new Vec(0, 0, 0), new Vec(3.14159*2.0,0,0), GamerParams.decimal);
		JDouble arm3 = new JDouble("Arm 3", g.arm3, new Vec(0, 0, 0), new Vec(3.14159*2.0,0,0), GamerParams.decimal);
		JDouble arm4 = new JDouble("Arm 4", g.arm4, new Vec(0, 0, 0), new Vec(3.14159*2.0,0,0), GamerParams.decimal);
    
//		JDouble bulge_size = new JDouble("Bulge size", g.bulge_size, new Vec(0, 0, 0), new Vec(100,0,0), GamerParams.decimal);
		JDouble bulge_dust = new JDouble("Bulge dust", g.bulge_dust, new Vec(0, 0, 0), new Vec(1,0,0), GamerParams.decimal);

		JDouble warp_scale = new JDouble("Warp scale", g.warpScale, new Vec(0, 0, 0), new Vec(100,0,0), GamerParams.decimal);
		JDouble warp_amplitude = new JDouble("Warp amplitude", g.warpAmplitude, new Vec(0, 0, 0), new Vec(8,0,0), GamerParams.decimal);

		JMyCombo innerTwirl = new JMyCombo("Has innertwirl", g.innerTwirl, GamerParams.yesno, GamerParams.yesnoVals);

		JDouble winding_B = new JDouble("Winding B", g.winding_B, new Vec(0, 0, 0), new Vec(50,0,0), GamerParams.decimal);
		JDouble winding_N = new JDouble("Winding N", g.winding_N, new Vec(0, 0, 0), new Vec(50,0,0), GamerParams.decimal);
		
		add(new JTripleValue(no_arms, arm1, arm2, arm3,arm4));

		add(new JTripleValue(new JLabel("Bulge properties"), innerTwirl, null, bulge_dust));

		add(new JTripleValue(new JLabel("Warp properties"), warp_scale, warp_amplitude, null));

		add(new JTripleValue(new JLabel("Winding properties"), winding_N, winding_B, null));

	}
	

}
